package com.tone.ji_volunteer.controller;

import com.tone.ji_volunteer.interceptor.LoginCheckInterceptor;
import com.tone.ji_volunteer.pojo.Result;
import com.tone.ji_volunteer.service.ActivityService;
import com.tone.ji_volunteer.util.JWT;
import com.tone.ji_volunteer.util.OssUpload;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author tone(ang)
 * version 1.0
 */
@Slf4j
@RestController
public class UploadController {
    @Autowired
    private OssUpload ossUpload;
    @Autowired
    private ActivityService activityService;

    @PostMapping("/upload")
    public Result upload(@RequestHeader("X-Activity-ID") Integer activityID, MultipartFile image) throws IOException {
        log.info("massage: {}", image);
        System.out.println(activityID);
        //使用OSS. 返回的是url
        String upload = ossUpload.upload(image);
        //将url添加到数据库
        activityService.addImages(upload, activityID);
        return Result.success(upload);
    }
}
